<?php
declare (strict_types=1);

namespace app\common\model;

class UserNotify extends Base
{
    protected function user(): object
    {
        return $this->hasOne(User::class, 'id', 'uid')
            ->field('id,code,nickname,mobile,photo');
    }

    protected function getStatusNameAttr($value, $data): string
    {
        return $data['status'] ? '已读' : '未读';
    }

    protected function getTypeNameAttr($value, $data): string
    {
        return getNotifyType($data['type_id']);
    }

    public static function add($type_id, $uid, $title, $content, $order_id = ''): void
    {
        parent::create([
            'type_id' => $type_id,
            'uid' => $uid,
            'title' => $title,
            'content' => $content,
            'order_id' => $order_id
        ]);
    }
}